import AbpBase from '../../lib/abpbase'
import { Component, Vue,Inject, Prop,Watch } from 'vue-property-decorator';

@Component
export default class OrderBase extends AbpBase{
	get expresses() {
		return {
			"HTKY": "百世快递",
			"DEPPON": "德邦",
			"GTO": "国通",
			"JD": "京东",
			"STO": "申通",
			"SFEXPRESS": "顺丰",
			"TTKDEX": "天天",
			"CHINAPOST": "邮政包裹",
			"YTO": "圆通",
			"YUNDA": "韵达",
			"ZTO": "中通",
			"INTMAIL": "邮政国际包裹"
		}
	}
	getOrderStatus(order) {
		if(order.info.status == 0) {
			// 订单已创建
			var p = order.paymentInfo.paymentStatus;
			var s = order.shipInfo.shipStatus;
			// 常见情况
			if(p == 0) {
				if(s == 0) {
					return order.paymentInfo.paymentType == 1 ? '等待发货' : '待付款';
				}else if(s == 1) {
					return '已发货';
				}else if(s == 10) {
					return '待收货';
				}else if(s == 11) {
					return '已收货, 待付款';
				}
			}else if(p == 2) {
				if(s == 0) {
					return '已付款, 等待发货';
				}else if(s == 1) {
					return '已发货';
				}else if(s == 10) {
					return '待收货';
				}else if(s == 11) {
					return '已收货';
				}
			}
			// 其他情况
			return {
				0: '待付款', 
				1: '正在付款', 
				2: '已付款', 
				10: '待退款', 
				11: '正在退款', 
				12: '已退款'
			}[order.paymentInfo.paymentStatus] + '，' + {
				0: '等待发货', 
				1: '已发货', 
				10: '待收货', 
				11: '已收货', 
				20: '等待退货', 
				21: '正在退货', 
				22: '已退货'
			}[order.shipInfo.shipStatus];
		}else if(order.info.status == 1) {
			// 交易成功
			return "交易成功";
		}else if(order.info.status == 2) {
			// 交易关闭
			return "交易关闭";
		}
    }
    getPaymentType(order) {
        return ["在线支付", "货到付款", "银行转账"][order.paymentInfo.paymentType];
	}
	canDeleteOrder(order) {
		return order.info.status == 2;
	}
	canFinishOrder(order) {
		return order.info.status == 0 && order.paymentInfo.paymentStatus == 2 && order.shipInfo.shipStatus == 11;
	}
	canModifyOrder(order) {
		return order.info.status == 0 && order.paymentInfo.paymentStatus == 0 && order.shipInfo.shipStatus == 0;
	}
	canShipOrder(order) {
		return order.info.status == 0 && order.shipInfo.shipStatus == 0;
	}
	canConfirmPayment(order) {
		return order.info.status == 0 && order.paymentInfo.paymentStatus == 0;
	}
	canRefund(order) {
		return order.paymentInfo.paymentStatus == 2;
	}
	async handleDeleteOrder(orderNumber:string, callback?:Function){
		this.confirm('确认删除该订单吗？', async () => {
			var response = await this.delete('AdminOrderManager/Delete', { orderNumber: orderNumber });
			if(response.success && callback) {
				callback();
			}
		})
	}
	async handleFinishOrder(orderNumber:string, callback?:Function){
		this.confirm('确认完成该订单吗？', async () => {
			var response = await this.delete('AdminOrderManager/SetFinish', { orderNumber: orderNumber });
			if(response.success && callback) {
				callback();
			}
		})
	}
}